﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">

        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="用户名" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<script>
    $(function () {
        gridList();
    })
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/SystemManage/UserLogin/GetGridJson",
            height: $(window).height() - 128,
            //rowNum: 20,
            colModel: [
                { label: '主键', name: 'Id', hidden: true },
                { label: '租户Id', name: 'TenantId', width: 100, align: 'center' },
                { label: '租户名', name: 'UserName', width: 100, align: 'center' },
                { label: '用户Id', name: 'UserId', width: 100, align: 'center' },
                { label: '用户名', name: 'UserName', width: 100, align: 'center' },
                {
                    label: '操作类型', name: 'OperateType', width: 100, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 'Login') {
                            return '<span class=\"label label-success\">登入</span>';
                        }
                        else if (cellvalue == 'Logout') {
                            return '<span class=\"label label-warning\">登出</span>';
                        }
                    }
                },

                { label: '操作时间', name: 'OperateTime', width: 100, align: 'center' },
                {
                    label: '操作结果', name: 'OperateResult', width: 100, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == true) {
                            return '<span class=\"label label-success\">登录成功</span>';
                        }
                        else if (cellvalue == false) {
                            return '<span class=\"label label-danger\">登录失败</span>';
                        }
                    }
                },
                {
                    label: 'IP地址', name: 'IpAddress', width: 100, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == '127.0.0.1' || cellvalue == '::1' || cellvalue == 'localhost') {
                            return cellvalue + '&nbsp&nbsp' + '本地';
                        }
                        else {
                            return cellvalue + '&nbsp&nbsp' + rowObject.IpAddressLocation;
                        }
                    }
                },
                { label: '备注', name: 'Description', width: 200, align: 'left' }
            ],
            pager: "#gridPager",
            sortname: 'CreatorTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
</script>